import axios from 'axios';
import query from 'query-string';
import { getCurrentInstance } from 'vue';

const BASE_URL = '/wms/warehouse';

export interface WarehouseResponse {
    id?: number;
    supplierName: string;
    warehouseName?: string;
    warehouseType: number;
    warehouseAddress?: string;
    warehouseAdminName?: string;
    warehouseAdminPhone?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

// 管理员添加命令
export interface WarehouseSaveCommand {
    id?: number;
    supplierName: string;
    warehouseName?: string;
    warehouseType: number;
    warehouseAddress?: string;
    warehouseAdminName?: string;
    warehouseAdminPhone?: string;
}

export interface WarehouseParam {
    warehouseName?: string;
    status?: number;
    startCreatedAt?: string;
    endCreatedAt?: string;
    page?: number,
    size?:number,
    sort?:Array<string>;
}

export interface WarehouseResponseList {
    list: WarehouseResponse[];
    total: number;
}

// 通过id获取管理员详情信息
export function getWarehouse(id: number) {
    return axios.get<WarehouseResponse>(`${BASE_URL}/${id}`);
}

// 通过WarehouseParam参数获取分页列表
export function pageWarehouse(params: WarehouseParam) {
    return axios.get<WarehouseResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 添加管理员
export function addWarehouse(params: WarehouseSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新管理员
export function updateWarehouse(params: WarehouseSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}


// 批量删除管理员
export function deleteWarehouse(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}